// main.js
const { Worker, MessageChannel } = require("worker_threads");

const worker = new Worker("./worker.js"); // 引用 worker.js 文件
const channel = new MessageChannel();

// 从工作线程接收消息
channel.port1.on("message", (message) => {
  console.log("Received from worker:", message);
});

// 向工作线程发送消息
worker.postMessage({ port: channel.port2 }, [channel.port2]);
